import Vue from 'vue'

// dictionary
Vue.filter('dictionary', function(val, data, type) {
    if (type == 'dictItemCode') {
        for (let i = 0; i < data.length; i++) {
            if (data[i].dictItemCode == val) {
                return data[i].dictItemName
            }
        }
    } else if (type == 'CODE_VALUE') {
        for (let i = 0; i < data.length; i++) {
            if (data[i].codeValue == val) {
                return data[i].codeName
            }
        }
    } else if (type == 'multiple') {
        let list = []
        for (let i = 0; i < data.length; i++) {
            let valData = val.split(",")
            for (let ii = 0; ii < valData.length; ii++) {
                if (data[i].codeValue == valData[ii]) {
                    list.push(data[i].codeName)
                }
            }
        }
        return list.join(",")
    } else {
        for (let i = 0; i < data.length; i++) {
            if (data[i].code == val) {
                return data[i].value
            }
        }
    }
    return val
})
